package com.unionServer.models;


import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;


public class GatewayMessage {
    final private int messageLength;
    final private String message;
    final private String numString;
    final private byte[] byteMessage ;

    public GatewayMessage(int messageLength, String message, String numString) {
        this.messageLength = messageLength;
        this.message = message;
        this.numString = numString;
        this.byteMessage = null;
    }
    public GatewayMessage(int messageLength, String message,byte[] byteMessage, String numString) {
        this.messageLength = messageLength;
        this.message = message;
        this.numString = numString;
        this.byteMessage = byteMessage;
    }

    public int getMessageLength() {
        return messageLength;
    }

    public byte[] getByteMessage() {
        return byteMessage;
    }
    public String getMessage() {
        return message;
    }
    public String getNumString() {
        return numString;
    }
    public byte[] getByteArray() throws UnsupportedEncodingException {
        return (numString+message).getBytes( StandardCharsets.US_ASCII);
    }

    public GatewayMessage getMessageWithoutId() {

        String newMessage =this.message;
        byte[] newByteMessage = this.byteMessage;
        int newMessageLength = newMessage.length();
        String newNumString = (new DecimalFormat("0000")).format(newMessageLength);

        return new GatewayMessage(newMessageLength, newMessage,newByteMessage, newNumString);


    }
    public GatewayMessage getMessageWithID(String id) {

        String newMessage =this.message;
        byte[] newByteMessage = this.byteMessage;
        int newMessageLength = newMessage.length();
        String newNumString = (new DecimalFormat("0000")).format(newMessageLength);

        return new GatewayMessage(newMessageLength, newMessage, newNumString);
    }

    public String getID() {
          return "111";
    }

}
